<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use App\Models\Project;

Route::group([
    'namespace' => 'Web',
    'middleware' => 'debug'
], function ($api) {

    $api->get('api/backstage/project/downloads/{id}', function ($id) {
        $model = Project::find($id);
        return \Storage::download('public/' . $model->path);
    });

    /**
     * 主页面
     */
    $api->get('/', 'IndexController@index')->middleware(['region']);

    $api->get('/strategy', 'StrategyController@index')->middleware('region');

    $api->get('/designer', 'DesignerController@index')->middleware('region');

    $api->get('/case', 'CaseController@index')->middleware('region');

    $api->get('/biaoqian', 'LabelController@index')->middleware('region');
    $api->get('/biaoqian/{id}', 'LabelController@find')->middleware('region');

    /**
     * 站点切换
     */
    $api->get('/region', 'RegionController@index')->middleware('region');

    $api->get('company', 'CompanyController@index')->middleware(['region']);
    $api->get('company/detail/{id}', function ($id) {
        return redirect(url('company', $id), 301);
    });
    $api->get('company/{id}', 'CompanyController@detail')->middleware('region')->where(['id' => '[0-9]+']);

    $api->get('jiancaiku', 'CompanyController@list')->middleware('region');
    $api->get('jiancaiku/{uri}', 'CompanyController@material')->middleware('region')->where(['uri' => '[a-z]+']);
    $api->get('jiancaiku/{uri?}/detail/{id}', function ($uri = null, $id) {
        return redirect(url('jiancaiku', $id), 301);
    });
    $api->get('jiancaiku/{id}', 'CompanyController@materialDetail')->middleware('region')->where(['id' => '[0-9]+']);

    $api->get('jiaju', 'FurnitureController@list')->middleware('region');
    $api->get('jiaju/{uri}', 'FurnitureController@jiaju')->middleware('region')->where(['uri' => '[a-z]+']);

    $api->get('jiaju/{uri?}/detail/{id}',  function ($uri = null, $id) {
        return redirect(url('jiaju', $id), 301);
    });
    $api->get('jiaju/{id}', 'FurnitureController@jiajuDetail')->middleware('region')->where(['id' => '[0-9]+']);



    $api->group([
        'namespace' => 'Baike',
        'prefix' => 'baike'
    ], function ($api) {
        $api->get('detail/{id}', function ($id) {
            return redirect(url('baike', $id), 301);
        });

        $api->get('index', 'EncyclopediasController@index');

        $api->get('/{id}', 'DetailController@detail')->where(['id' => '[0-9]+']);

        $api->get('/{code}', 'EncyclopediasController@column')->where(['name' => '[a-z]+']);
    });
});